/*
 * Copyright 2018-10-17 7:49:26 The JA-SIG Collaborative. All rights reserved.
 * distributed with thi file and available online at
 */
package com.lap.scp.erp.ao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lap.scd.commons.ao.AbstractAO;
import com.lap.scd.commons.constant.RespCode;
import com.lap.scd.commons.page.Page;
import com.lap.scd.commons.page.PageResult;
import com.lap.scd.commons.page.PageUtils;
import com.lap.scd.commons.result.Resp;
import com.lap.scp.erp.ao.ReceivablesDetailAO;
import com.lap.scp.erp.core.ReceivablesDetailManager;
import com.lap.scp.erp.domain.ReceivablesDetailDO;
import com.lap.scp.erp.query.ReceivablesDetailQueryVO;

/**
 * <pre>
 *   默认 收款明细应用实现类，提供收款明细相关的流程应用操作、查询等。
 *
 * </pre>
 * 
 * @author 劳水生 Exp
 * @Date 2018-10-17 7:49:26
 * @since 2.0.0
 */
@Service("receivablesDetailAO")
public class DefaultReceivablesDetailAO extends AbstractAO implements ReceivablesDetailAO {
	/**
	 * 收款明细业务操作对象
	 */
	@Resource
	private ReceivablesDetailManager receivablesDetailManager;

	@Override
	public Resp<ReceivablesDetailDO> insertReceivablesDetail(ReceivablesDetailDO receivablesDetailDO) {
		Resp<ReceivablesDetailDO> resp = new Resp<>();
		try {
			if (resp.isSuccess()) {
				receivablesDetailManager.insertReceivablesDetail(receivablesDetailDO);
				resp.setData(receivablesDetailDO);
			}
		} catch (Exception e) {
			resp.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(receivablesDetailDO, e);
		}
		return resp;
	}

	@Override
	public PageResult<ReceivablesDetailDO> queryPage(Page page, ReceivablesDetailQueryVO queryVO) {
		PageResult<ReceivablesDetailDO> pr = new PageResult<>();
		try {
			List<ReceivablesDetailDO> list = receivablesDetailManager.queryPage(page, queryVO);

			PageUtils.copyPage(pr, page);
			pr.setData(list);
		} catch (Exception e) {
			pr.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(new Object[] { page, queryVO }, e);
		}
		return pr;
	}

	@Override
	public Resp<List<ReceivablesDetailDO>> queryByReceivablesId(Integer receivablesId) {
		Resp<List<ReceivablesDetailDO>> resp = new Resp<>();
		try {
			List<ReceivablesDetailDO> list = receivablesDetailManager.queryByReceivablesId(receivablesId);
			resp.setData(list);
		} catch (Exception e) {
			resp.putMsg(RespCode.Error, super.getMsg("505", new String[] { e.getLocalizedMessage() }));
			super.writeLog(receivablesId, e);
		}
		return resp;
	}

}
